package com.example.api.exception;


import com.example.api.dto.ErrorRes;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
/**
 *  @Author: wangxinlei
 *  @Date: 2020/9/8 19:23
 *  @Description: 自定义异常处理器
 */
@RestControllerAdvice
public class CustomExceptionHandler {

    @ExceptionHandler(CustomException.class)
    @ResponseStatus(HttpStatus.NOT_ACCEPTABLE)
    public ErrorRes handlerException(CustomException ex, HttpServletResponse response){
        return new ErrorRes(ex.getBizId(),ex.getStatus(),ex.getMessage());
    }

}
